import pandas as pd
import numpy as np

 
myTeam='COL'
myYear='2013'
minAB = 100

mydat=pd.read_csv('Batting.csv',parse_dates=['yearID'])
pl=mydat[(mydat['teamID']==myTeam) & (mydat['yearID']==myYear+'-01-01') & (mydat['AB']>minAB)]
pl['BA']=pd.Series(pl.H/pl.AB)
pl['SLG']=pd.Series((pl.H+1.*pl['2B']+2.*pl['3B']+3.*pl.HR)/pl.AB)
pl['OBA']=pd.Series((pl.H+pl.BB+pl.IBB+pl.HBP)/(pl.AB+pl.BB+pl.IBB+pl.SH+pl.SF))
pl['TB']=pd.Series((pl.H+1.*pl['2B']+2.*pl['3B']+3.*pl.HR))
pl['E']=pd.Series(data=np.zeros(pl.shape[0]),index=pl['playerID'].index,dtype='int64')
pl['BB']+=pl['IBB']
pl['R']=pl['R'].astype('int64')
pl['H']=pl['H'].astype('int64')
pl['AB']=pl['AB'].astype('int64')
pl['G']=pl['G'].astype('int64')
pl['TB']=pl['TB'].astype('int64')
pl['2B']=pl['2B'].astype('int64')
pl['3B']=pl['3B'].astype('int64')
pl['HR']=pl['HR'].astype('int64')
pl['RBI']=pl['RBI'].astype('int64')
pl['BB']=pl['BB'].astype('int64')
pl['SO']=pl['SO'].astype('int64')
pl['SB']=pl['SB'].astype('int64')
pl['CS']=pl['CS'].astype('int64')
pl.to_csv('/tmp/mynew.csv',sep='\t',float_format="%.3f",index=False,header=True,columns=['playerID','BA','SLG','OBA','G','AB','R','H','TB','2B','3B','HR','RBI','BB','SO','SB','CS','E'])
